package util

import (
	"fmt"
	"github.com/jlaffaye/ftp"
	"io/ioutil"
	"log"
	"time"
)

func Download() {
	const HOST = "61.172.176.213"
	const PORT = "5003"
	const USER = "SMPICS"
	const PASSWORD = "smpics123"

	con, err := ftp.Dial(HOST+":"+PORT, ftp.DialWithTimeout(60*time.Second))
	if nil != err {
		log.Fatal(err)
		return
	}

	//登录ftp
	err = con.Login(USER, PASSWORD)
	if err != nil {
		log.Fatal(err)
	}

	fileList, err := con.NameList("/VIDEO")

	log.Fatal(fileList)
	fmt.Println(con.List("/VIDEO"))

	resp, err := con.Retr("/VIDEO/NW001新弘站_20190613162111_20190613162214.dav")
	buf, err := ioutil.ReadAll(resp)
	err = ioutil.WriteFile("test.dav", buf, 0777)
	//entry,err := con.List("/VIDEO")
	log.Fatal(err)
	//断开连接
	if err := con.Quit(); err != nil {
		log.Fatal(err)
	}

}
